﻿using System;
using AppCommon;
using Controller;
using Model;

public partial class admincenter_DeletePost : System.Web.UI.Page
{
    public static string _idPost = "";
    protected void Page_Load(object sender, EventArgs e)
    {        
        if (!IsPostBack)
        {
            if (Session[Constants.S_ADMIN_USER] != null)
            {
                // Ok
            }
            else
            {
                Response.Redirect("~/admincenter/");
            }

            // Get id post
            string idPost = Request.QueryString["Id"];
            if (idPost != null)
            {
                _idPost = idPost;
            }
            else
            {
                Response.Redirect("~/admincenter/Error.aspx");
            }
        }
    }

    public int DeleteAPost(Post post)
    {
        var postController = new PostController();
        return postController.DeletePost(post);
    }

    protected void btnXoa_OnClick(object sender, EventArgs e)
    {
        var post = new Post {Id = _idPost};
        Response.Redirect(DeleteAPost(post) > 0 ? "~/admincenter/PostsManager.aspx" : "~/admincenter/Error.aspx");
    }

    protected void btnHuy_OnClick(object sender, EventArgs e)
    {
        Response.Redirect("~/admincenter/PostsManager.aspx");
    }
}